<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        // 请把俩个数组 [A1, A2, B1, B2, C1, C2, D1, D2] 和 [A, B, C, D]，合并为 [A1, A2, A, B1, B2, B, C1, C2, C, D1, D2, D]。
        let cc = ['A', 'B', 'C', 'D'].join()
        let dd = ['A1', 'A2', 'B1', 'B2', 'C1', 'C2', 'D1', 'D2']
        console.log(cc)
        dd.forEach((item, index) => {
            // 如果A1,A2zaiABCD且个位为2则在A2后面加A
            if (item[1] == 2) {
                dd.splice(index + 1, 0, item[0])
            }
        })
        // 最后一个
        if (dd[dd.length - 1].charAt(1) == 2) {
            dd.push(dd[dd.length - 1].charAt(0))
        }
        console.log(dd)
    </script>
</body>

</html>